
#    This file is part of pyCorreios.
#    
#    pyCorreios is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    
#    pyCorreios is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    
#    You should have received a copy of the GNU General Public License
#    along with pyCorreios.  If not, see <http://www.gnu.org/licenses/>.

# 
# CODE
# 
def parseNacional(html):
    lines = html.split("\n")
    
    status = "searching"
    
    items = []
    
    for line in lines:
        if status == "searching":
            if line.startswith("<table"):
                status = "inside_table"
        elif status == "inside_table":
            if line.startswith("<tr><td rowspan"):
                item = []
                for blocks in line.split('>'):
                    if not blocks.startswith('<') and len(blocks) > 1:
                        item.append(blocks[:blocks.index('<')])
                
                items.append(item)
                        
            elif line.startswith("<tr><td colspan="):
                for blocks in line.split('>'):
                    if not blocks.startswith('<') and len(blocks) > 1:
                        items[-1].append(blocks[:blocks.index('<')])
            elif line.endswith("TABLE>"):
                status = "finished"
                break
    return items
# def parseNacional()